<template>
  <transition name="slide">
    <music-list :title="title" :bg-image="bgImage" :songs="songs" ></music-list>
  </transition>
</template>

<script type="text/ecmascript-6">
  import musicList from '../../components/music-list/music-list.vue'
  import { getRankingList } from '../../api/rank'
  import { createRankSongs } from '../../common/js/song'
  import { mapGetters } from 'vuex'

  export default {
    data () {
      return {
        songs: []
      }
    },
    computed: {
      title () {
        return this.topList.topTitle
      },
      bgImage () {
        return this.topList.picUrl
      },
      ...mapGetters([
        'topList'
      ])
    },
    created () {
      this._getRankingList()
    },
    methods: {
      _getRankingList () {
        getRankingList(this.topList.id, (res) => {
          if (res.data.detail) {
            const songList = (res.data.detail.data.songInfoList)
            this.songs = this._normalLizeSong(songList)
          }
        })
      },
      _normalLizeSong (list) {
        let ret = []
        list.forEach((item) => {
           ret.push(createRankSongs(item))
        })
        return ret
      }
    },
    components: {
      musicList
    }
  }

</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  .slide-enter-active, .slide-leave-active
    transition: all 0.3s ease

  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)
</style>